package tests;//package com.mika.music.tests;


import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import utils.AutoTestUtils;

import java.io.IOException;

public class RegistryPage extends AutoTestUtils {
    public static String url = "http://114.55.226.213:8080/register.html";

    public RegistryPage() {
        super(url);
    }

    public void registryFail() throws IOException {
        // 先清空输入框
        driver.findElement(By.xpath("//*[@id=\"user\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();

        // 输入被注册过的账号
        driver.findElement(By.xpath("//*[@id=\"user\"]")).sendKeys("mika");
        driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys("123");
        driver.findElement(By.xpath("//*[@id=\"submit\"]")).click();
        AutoTestUtils.getScreenshot("registryFail");
    }

    public void registrySuc() throws IOException, InterruptedException {
        // 先清空输入框
        driver.findElement(By.xpath("//*[@id=\"user\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"password\"]")).clear();
        // 账户密码都是空的测试
        driver.findElement(By.xpath("//*[@id=\"submit\"]")).click();
        AutoTestUtils.getScreenshot("registrySuc");


        // 未注册的账号密码
        driver.findElement(By.xpath("//*[@id=\"user\"]")).sendKeys("mika1111113");
        driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys("123");
        driver.findElement(By.xpath("//*[@id=\"submit\"]")).click();

        // 截图看看到底注册成没成功
        Thread.sleep(1500);
        Alert alert = driver.switchTo().alert();
        //确认弹窗
        alert.accept();
        System.out.println("测试注册成功后，是否跳转到登录页面: " + driver.getTitle());
        AutoTestUtils.getScreenshot("registrySuc");
        
    }

}
